#ifndef ZIGBEENODE_H
#define ZIGBEENODE_H

#include <QGraphicsItem>
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QPainter>
#include <QStyleOption>
#include <QPoint>
#include "itemtype.h"
#include "model/node.h"




class Edge;

/**
 * @brief The info struct
 */
struct info {
    info():m_value(0),m_time("xxxx:xx:xx"){

    }

    int m_value;//值
    QString m_time;//时间

};

/**
 * @brief The ZigBeeNode class 节点只删除它自身链接到它父节点的边缘线
 */
class ZigBeeNode :/*public QObject,public QGraphicsItem*/public QGraphicsObject
{

    Q_OBJECT
public:
    //enum{Type=ZigNodeItemType};
    explicit ZigBeeNode(const Node &m,const QPoint &position,QGraphicsScene *scene);
    void addEdge(Edge *edge);
    int type() const { return Devicetype; }
    QList<Edge *> &edges() ;
    QRectF boundingRect() const;
    QPainterPath shape() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    bool advance();
    void calculateForces();
    // void Setstate(bool state);
    bool getState()const{return Nodestate;}
    Node* ge_NodeData() {return &m_node;}
    info getNow() {return m_now;}
    /**
     * @brief changeStatus 改变节点的状态
     * @param status
     */
    void changeStatus(bool status);

    void setParentNode(ZigBeeNode *node);
    void deleteParentEdge();


    void deleteAedge(Edge *ed);
    void clearEdgeList();

    void setTime(const QString& tm) {
        m_now.m_time = tm;
    }
    void setValue(int value) {
        m_now.m_value = value;
    }

protected:
    QVariant itemChange(GraphicsItemChange change, const QVariant &value);
    void mousePressEvent(QGraphicsSceneMouseEvent *event);
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);

private:
    /**
     * @brief Nodestate 节点状态
     */
    bool Nodestate;
    QList<Edge*> edgeList;
    QPointF newPos;
    int Devicetype;
    /**
     * @brief m_node
     */
    // Node* m_node;
    Node m_node;
    /**
     * @brief The info struct 记录实时的信息
     */



    info m_now;

    ZigBeeNode* p_parent;

};

#endif // ZIGBEENODE_H

